import NumberShow from "../number/NumberShow";
import { Constant } from "../constant/Constant";

// Learn TypeScript:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/typescript.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html

const { ccclass, property } = cc._decorator;

@ccclass
export default class AddScoreNode extends cc.Component {

    @property(cc.Node)
    scoreAdder: cc.Node = null;



    start() {

    }
   
    private count: number = 0;//碰撞计数器

    /**
     * 加分逻辑
     * @param other
     */
    onCollisionEnter(other: cc.Component) {
        let otherNode = other.node;
        let t = this;
        if (otherNode.name == "Left") t.count++;
        if (otherNode.name == "Right") t.count++;
        if (t.count == 2) {
            t.count = 0;
            Constant.NOW_SCORE ++;
            t.scoreAdder.getComponent(NumberShow).showNumber( Constant.NOW_SCORE);
        }
    }

    onCollisionExit(other: cc.Node) {
        // cc.log("exit" + other.name);
        // let name = other.name;
        // if (name == "left" || name == "right") {
        //     cc.log("exit");
        // }
    }

    onCollisionStay(other: cc.Node) {
        // cc.log("stay" + other.name);
        // let name = other.name;
        // if (name == "left" || name == "right") {
        //     cc.log("stay");
        // }
    }

    update(dt) {

    }
}
